﻿//Copyright (C) <2013>  <jonathan cleeve norton> All Rights Reserved 
//Contact jon.norton@fin-plus.co.uk website <http://www.fin-plus.co.uk/>
using System;
using System.Windows.Controls;
using FinPlusCommon;
using log = Logger.Logger;

namespace FinPlusWPFControls
{
    public partial class FinPlusStackPanel : FinPlusControl
    {
        public override string[] States { get { return new string[] { "Height", "Width", "Left", "Top" }; } }
        public override string[] TestStates { get { return new string[] { "TestString", "ChildrenCount", "IsValid" }; } }
        public override IFunctions Adaptor { get { return base.Children(stackPanel.Children); } }
              
        public int ChildrenCount { get { return stackPanel.Children.Count; } }

        //construct
        public FinPlusStackPanel(IFinPlusComp[] controls)
        {
            InitializeComponent();

            foreach(var control in controls)
                stackPanel.Children.Add((UserControl)control);

            IsValid = true;
        }

        //common control interface
        public override void Dock(object control, string dock)
        {
            try
            {
                if (control.GetType().Equals(typeof(Exception)))
                    stackPanel.Children.Add(new FinPlusErrorDisplay((Exception)control));
                else
                    stackPanel.Children.Add((UserControl)control);

            }
            catch (Exception e)
            {
                IsValid = log.Log(Logger.Level.Warning, Id, Config, e.Message, e);
                stackPanel.Children.Add(new FinPlusErrorDisplay(e));
            }
        }
    }
}
